package com.example.mqreceiver.processor;

import com.alibaba.fastjson.JSON;
import com.example.mqreceiver.AbstractMQEventProcessor;
import com.example.mqreceiver.event.BusinessOneEvent;
import enums.EventTypeEnum;
import event.BusinessEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;


/**
 * 具体的业务处理器
 * @author ke
 * Created by on  2021-05-27 10:02
 */
@Component
@Slf4j
public class BusinessOneProcessor extends AbstractMQEventProcessor {

    @Override
    public boolean condition(BusinessEvent event) {
        // TODO: 2021/5/21 事件触发前置条件
        return true;
    }

    @Override
    protected void processEvent(BusinessEvent event) {
        //TODO 具体的业务处理操作在此处
        log.info("消费消息：{}",JSON.toJSON(event));
    }

    @Override
    protected void setEventIdentifier(BusinessEvent event) {
        BusinessOneEvent activityInvitedEvent = (BusinessOneEvent) event;
        String eventIdentifier = getEventIdentifier(
                activityInvitedEvent.getEventType().getType(),
                activityInvitedEvent.getBusinessId());
        activityInvitedEvent.setEventIdentifier(eventIdentifier);
    }

    @Override
    public EventTypeEnum getEventType() {
        return EventTypeEnum.BUSINESS_ONE;
    }
}